(function () {
    $.fn.extend({
        flyCart() {
            var self = this
            var res1
            var arr1 = []
            var res2
            var arr2 = []
            $('.addCart').on('click', function () {
                Array.from($('.BoxSize').find('span')).forEach(function (item) {

                    res1 = $(item).hasClass('active')
                    arr1.push(res1)
                })
                var Res1 = arr1.some(function (item) {
                    return item == true
                })
                Array.from($('.goodsColor').find('a')).forEach(function (item) {
                    res2 = $(item).hasClass('select')
                    arr2.push(res2)
                })
                var Res2 = arr2.some(function (item) {
                    return item == true
                })
                if (Res1 == true && Res2 == true) {
                    let $cloneImg = self.find('img').clone(true)
                    let $cloneLi = $('#cart_list').clone(true)
                    $cloneLi.prepend($cloneImg)
                    let x = self.find('img').offset().left
                    let y = self.find('img').offset().top
                    $cloneImg.css({
                        position: 'absolute',
                        left: x - 457.5,
                        top: y - 177
                    })
                    self.find('a').append($cloneImg)
                    let mX = $('.cartbox').offset().left
                    let mY = $('.cartbox').offset().top + $('.cartbox').height()
                    $cloneImg.stop().animate({
                        left: mX - 457.5,
                        top: mY - 177,
                        height: 0,
                        width: 0
                    }, function () {

                        this.remove()
                    })
                    arr1 = []
                    arr2 = []
                } else {
                    arr1 = []
                    arr2 = []
                    return
                }
            })
        }
    })
})()
$(function () {
    $('#goods_Img').flyCart()
})